package com.red.wood.dubbo.dao.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import com.red.wood.dubbo.dao.CdnBusinessDataDao;

@Repository
public class CdnBusinessDataDaoImpl implements CdnBusinessDataDao{

	@Autowired
	private JdbcTemplate jdbcTemplate;
	
	@Override
	public List<Map<String, Object>> getCdnDataInfo() {
		String sql = "select cdnid,cdnname,cdnadd,corp,timstamp from t_dwd_cdn_cdndata";
		return jdbcTemplate.queryForList(sql);
	}

	@Override
	public List<Map<String, Object>> getCdnNetInfo(int min, int max) {
		StringBuffer sql = new StringBuffer();
		sql.append("select *");
		sql.append("  from (select a.*, rownum rn");
		sql.append("          from (select t.cdnid,t.cdnnetid,t.topdomain,t.regid,t.domainid,t.timstamp from t_dwd_cdn_cdnnetinfo t) a");
		sql.append("         where rownum <= "+max+") aa");
		sql.append("  where rn > "+min);
		return jdbcTemplate.queryForList(sql.toString());
	}

	@Override
	public List<Map<String, Object>> getCdnIpInfo(int min,int max) {
		StringBuffer sql = new StringBuffer();
		sql.append("select *");
		sql.append("  from (select a.*, rownum rn");
		sql.append("          from (select t.cdnid,t.cdnnetid,t.nodeid,t.houseid,t.startip,t.endip,t.type,t.timstamp from t_dwd_cdn_node_house_ipseg t) a");
		sql.append("         where rownum <= "+max+") aa");
		sql.append("  where rn > "+min);
		return jdbcTemplate.queryForList(sql.toString());
	}

	@Override
	public List<Map<String, Object>> getCdnCustomerInfo(int min,int max) {
		StringBuffer sql = new StringBuffer();
		sql.append("select *");
		sql.append("  from (select a.*, rownum rn");
		sql.append("          from (select t.cdnid,t.customerid,t.unitname,t.unitnature,t.address,t.timstamp from t_dwd_cdn_customerinfo t where t.address != 'null' and t.address is not null) a");
		sql.append("         where rownum <= "+max+") aa");
		sql.append("  where rn > "+min);
		return jdbcTemplate.queryForList(sql.toString());
	}

	@Override
	public List<Map<String, Object>> getCdnDomainInfo(int min,int max) {
		StringBuffer sql = new StringBuffer();
		sql.append("select *");
		sql.append("  from (select a.*, rownum rn");
		sql.append("          from (select t.cdnid,t.customerid,t.serviceid,t.domainid,t.domain,t.regid,t.topdomain,t.timstamp from t_dwd_cdn_custom_serv_domain t where t.cdnid is not null) a");
		sql.append("         where rownum <= "+max+") aa");
		sql.append("  where rn > "+min);
		return jdbcTemplate.queryForList(sql.toString());
	}

	@Override
	public List<Map<String, Object>> getCdnHouseInfo(int min, int max) {
		StringBuffer sql = new StringBuffer();
		sql.append("select *");
		sql.append("  from (select a.*, rownum rn");
		sql.append("          from (select t.cdnid,t.cdnnetid,t.nodeid,t.houseid,t.housename,t.housetype,t.houseadd,t.timstamp,t.houseprovince,t.housecity,t.housecounty");
		sql.append("                  from t_dwd_cdn_cdnnet_node_house t) a");
		sql.append("         where rownum <= "+max+") aa");
		sql.append("  where rn > "+min);
		return jdbcTemplate.queryForList(sql.toString());
	}

	@Override
	public List<Map<String, Object>> getCdnNodeInfo(int min,int max) {
		StringBuffer sql = new StringBuffer();
		sql.append("select *");
		sql.append("  from (select a.*, rownum rn");
		sql.append("          from (select t.cdnid,t.cdnnetid,t.nodeid,t.nodename from t_dwd_cdn_cdnnetinfo_node t) a");
		sql.append("         where rownum <= "+max+") aa");
		sql.append("  where rn > "+min);
		return jdbcTemplate.queryForList(sql.toString());
	}

	@Override
	public List<Map<String, Object>> getCdnLinkOfficerInfo() {
		String sql = "select t.cdnid,t.name,t.idtype,t.mobile from t_dwd_cdn_linkofficerinfo t";
		return jdbcTemplate.queryForList(sql);
	}

	@Override
	public List<Map<String, Object>> getCdnGetWayInfo(int min,int max) {
		StringBuffer sql = new StringBuffer();
		sql.append("select *");
		sql.append("  from (select a.*, rownum rn");
		sql.append("          from (select t.cdnid,t.cdnnetid,t.nodeid,t.houseid,t.bandwidth from t_dwd_cdn_node_house_gateway t) a");
		sql.append("         where rownum <= "+max+") aa");
		sql.append("  where rn > "+min);
		return jdbcTemplate.queryForList(sql.toString());
	}

}
